//
//  PhotoShowViewController.m
//  MantisIMSDKUI
//
//  Created by 陈志亮 on 2021/4/10.
//

#import "PhotoShowViewController.h"
#import "CommonHeader.h"

@interface PhotoShowViewController ()
@property(nonatomic,strong)UIImageView*imgView;
@end

@implementation PhotoShowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   self.view.backgroundColor =[UIColor jk_colorWithHexString:@"#FF14181A"];
   self.view.alpha=0.8;
    [self creatImgView];
    
    
    UITapGestureRecognizer*tapVC = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissFromParentVC)];
    [self.view addGestureRecognizer:tapVC];
    
    
    
}

-(void)creatImgView{
    
    UIImageView*imgView = [[UIImageView alloc]initWithFrame:self.view.frame];
    imgView.contentMode=UIViewContentModeScaleAspectFit;
    self.imgView =imgView;
  
    WS(weakSelf);
 
    [imgView nlShowHudLoadingWithText:@"正在加载"];
    [imgView setImageWithURL:[NSURL URLWithString:self.imgUrl] placeholder:[UIImage imageNamed:@""] options:YYWebImageOptionProgressive progress:^(NSInteger receivedSize, NSInteger expectedSize) {
       
    } transform:^UIImage * _Nullable(UIImage * _Nonnull image, NSURL * _Nonnull url) {
        
        return  image;
       
    } completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
        if (from == YYWebImageFromDiskCache) {
                   NSLog(@"load from disk cache");
               }
        [weakSelf.imgView nlHideHudLoading];
        
    }];
    
    
    

    [self.view addSubview:imgView];
    
    
}


-(void)showCurrentVC:(UIViewController*)baseVC{
    WS(weakSelf);
    [baseVC addChildViewController:self];
    [baseVC.view addSubview:self.view];
      weakSelf.view.frame=CGRectMake(0, weakSelf.view.jk_height, weakSelf.view.jk_width,weakSelf.view.jk_height );
    [UIView animateWithDuration:.1 animations:^{
        weakSelf.view.frame=CGRectMake(0, 0, weakSelf.view.jk_width, weakSelf.view.jk_height);
    }];
}

-(void)dismissFromParentVC{
    WS(weakSelf);
//    weakSelf.view.frame=CGRectMake(0, 0, IMSCREEN_HEIGHT, IMSCREEN_HEIGHT);
//    [UIView animateWithDuration:.2 animations:^{
//        weakSelf.view.frame=CGRectMake(0, IMSCREEN_HEIGHT, IMSCREEN_HEIGHT, IMSCREEN_HEIGHT);
//    } completion:^(BOOL finished) {
        [weakSelf.view removeFromSuperview];
        [weakSelf removeFromParentViewController];
//    }];
}





/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
